# @Time : 2021/4/13 14:53
# @Author : Fioman 
# @Phone : 13149920693
"""
和前端通信的工具接口,这个模块主要是用来发送前端消息的.
"""
import json
from tools.websocket_queue import WebSocketQueue
from tools.common_tools import image_to_string
from vision_process.image_operation import get_size_scale_image
import cv2 as cv


msgQueue = WebSocketQueue().websocketQueue

def send_login_usernames_to_ui(msg):
    """
    发送用户名的信息到前端
    :param msg:
    :return:
    """
    msgType = "loginUsernameState"
    send_msg_to_ui(msgType, msg)



def send_working_info_state_to_ui():
    """
    更新workinginfo的状态,这里
    :return:
    """
    msgType = "produceState"
    msg = {
        "val": 'workingInfo'
    }
    send_msg_to_ui(msgType, msg)


def send_produce_state_to_ui(msgVal):
    """
    发送生产作业的页面的状态信息
    :param msgVal 消息内容
    :return:
    """
    msgType = "produceState"
    send_msg_to_ui(msgType, msgVal)

def send_settings_state_to_ui():

    msgType = "settingsState"
    msg = {
        "val": 'workingInfo'
    }
    send_msg_to_ui(msgType, msg)


def send_order_state_to_ui(msg):
    """
    更新工单状态
    :param msg:使用的key值
    :return:
    """
    msgType = "orderStates"
    send_msg_to_ui(msgType, msg)
    
def send_flagData_state_to_ui(msg):
    msgType = "flagDataParams"
    send_msg_to_ui(msgType, msg)


def send_open_door_alarm_to_ui():
    msgType = "produceState"
    msgVal = {
        "val": "opendooralarm",
        "opendoorModalVisble": True,
    }
    send_msg_to_ui(msgType, msgVal)

def send_msg_to_ui(msgType, msg):
    """
    将websocketQueue的内容发送给前端.
    :param msgType: 消息类型
    :param msg: 消息内容
    :return:
    """
    msgQueue.put(json.dumps({msgType: msg}))
